//
//  zxlCircleView.m
//  裁剪图片
//
//  Created by zhangxulong on 15/10/16.
//  Copyright © 2015年 zhangxulong. All rights reserved.
//

#import "zxlCircleView.h"

@implementation zxlCircleView


-(void)setImageName:(NSString *)imageName
{
    _imageName = imageName;
    [self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGFloat ra = MIN(rect.size.width, rect.size.height) * 0.9;
    CGRect imageRect = CGRectMake(0, 0, ra, ra);
    CGContextAddEllipseInRect(context, imageRect);
    //多余的部分 剪切掉
    CGContextClip(context);
    //显示图片
    UIImage * image = [UIImage imageNamed:self.imageName];
    [image drawInRect:imageRect];
    //设置 边框颜色
    
    CGContextSetLineWidth(context, self.lineWidth);
    [self.borderColor set];
    CGContextAddEllipseInRect(context, imageRect);
    CGContextStrokePath(context);
    
}


@end
